package org.ms24846.service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.ms248462.domain.Feed;
import org.ms248462.domain.FeedMessage;
import org.ms248462.util.RSSFeedParser;

/**
 *
 * @author mszarl
 */
@ManagedBean(name="service")
@SessionScoped
public class RssService implements Serializable {

    private static String FEED_URL = "http://www.vogella.de/article.rss";
    private RSSFeedParser parser = new RSSFeedParser(FEED_URL);

    public List<FeedMessage> getNewMessages() {
        List<FeedMessage> messages = new ArrayList<FeedMessage>();
        Feed feed = parser.readFeed();
        for (FeedMessage message : feed.getMessages()) {
            messages.add(message);
        }
        return messages;
    }
}
